'''
Created on 2019年1月4日

@author: allan
'''
from bs4 import BeautifulSoup

import urllib.parse
import urllib.request


class MyClass(object):
    '''
    classdocs
    '''


    def __init__(self, params):
        '''
        Constructor

        '''
def getHtml2Response(url,data={}):
    headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
               #'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
               'Connection':'keep-alive',
               }
    #data = urllib.parse.urlencode(values)
    
    req = urllib.request.Request(url=url, headers=headers, method='GET')
    respons = urllib.request.urlopen(req)  
    return respons

def getHtml2Str(url):

    response_result = getHtml2Response(url).read()
    return response_result.decode('utf-8')

def getHtml2Soup(url):           
    return BeautifulSoup(getHtml2Str(url), 'html.parser')
        
def getHtml(url,values):
    headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
    
    data = urllib.parse.urlencode(values)
    response_result = urllib.request.urlopen(url+'?'+data).read()
    html = response_result.decode('utf-8')
    return html
        